# -------------------------------------------------------------------------
#  asm.S
# -------------------------------------------------------------------------

#include "cp0_regdef.h"
	
# -------------------------------------------------------------------------
# Data segment
# -------------------------------------------------------------------------

#define	KERNEL_BOOT_STACK_SIZE		0x4000

		.data
	
kernel_boot_stack_low_limit:
        .space  KERNEL_BOOT_STACK_SIZE
kernel_boot_stack_high_limit:

			
# -------------------------------------------------------------------------
# Code segment
# -------------------------------------------------------------------------

	.text
	.set nomove

	.globl	_start

# -------------------------------------------------------------------------
# Startup code
#    This is where the system boots from
#     1. Load the stackpointer 'sp' with top of initial stack.
#     2. Jump to application-specific 'pornos', the OS entry point (defined in a C-file).
# -------------------------------------------------------------------------
_start:
# Copying the exception handler code
	la $t0, handler_start
	la $t2, handler_end
	la $t1, 0xA0000180 # location of the handler
	subu $t2, $t2, $t0 # length of the handler
loop:
	lw $v0, ($t0)
	sw $v0, ($t1)
	addu $t0, 4
	addu $t1, 4
	subu $t2, 4
	bgez $t2, loop
	
	la	$sp, kernel_boot_stack_high_limit
	j	pornos


#---------------------------------------------------------------------------
# Exception vector code
# Jumps at the entry point of the exception handler
#---------------------------------------------------------------------------
	#.set noreorder
handler_start:
	.set noat
	addi $k1, $at, 0
	.set at
	j exception_handler
handler_end:	
	#.set reorder













